package com.sws.rel.ball;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sws.common.annotation.Log;
import com.sws.common.core.controller.BaseController;
import com.sws.common.core.domain.AjaxResult;
import com.sws.common.enums.BusinessType;
import com.sws.rel.service.IPersonDeviceRelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 人员-设备关联关系检查Controller
 * 
 * @author ball
 * @date 2023-08-05
 */
@RestController
@RequestMapping("/ball/person_device_rel")
@Api(value = "人员-设备关联关系检查", tags = {"人员-设备关联管理"})
public class PersonDeviceRelCheckController extends BaseController
{
    @Autowired
    private IPersonDeviceRelService personDeviceRelService;

    /**
     * 检查人员是否可以同步到指定设备
     * 如果关联记录不存在，返回true，表示可以执行同步操作
     * 如果关联记录已存在，返回false，表示不应重复操作
     * 
     * @param personPid 人员ID
     * @param deviceSn 设备SN
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('person:device:query')")
    @ApiOperation(value = "检查人员是否可以同步到指定设备", notes = "传入人员ID和设备SN，返回是否可以执行同步操作")
    @Log(title = "人员-设备关联检查", businessType = BusinessType.OTHER)
    @GetMapping("/check_relation")
    public AjaxResult checkPersonDeviceRelation(
            @ApiParam(value = "人员PID", required = true) @RequestParam("personPid") String personPid,
            @ApiParam(value = "设备序列号", required = true) @RequestParam("deviceSn") String deviceSn)
    {
        boolean canSync = personDeviceRelService.checkPersonDeviceRelNotExists(personPid, deviceSn);
        
        if (canSync) {
            return AjaxResult.success("该人员未在此设备上同步，可以执行同步操作", true);
        } else {
            return AjaxResult.success("该人员已在此设备上同步，无需重复操作", false);
        }
    }
} 